#ifndef PWM_H
#define PWM_H

#include <linux/hrtimer.h>
#include <linux/ktime.h>
#include <linux/gpio.h>

#define MS_TO_NS(x)    (x * 1E6)

struct gpio_pwm_desc_t
{
	struct hrtimer hr_timer;
	int gpio_pin;
	int frequency;
	int active;
	int polarity;
	int value;
	int duty_ticks;
	int period_ticks;
};

typedef struct gpio_pwm_desc_t gpio_pwm_desc;

gpio_pwm_desc* gpio_pwm_init(int);
void gpio_pwm_start(gpio_pwm_desc*);
void gpio_pwm_stop(gpio_pwm_desc *desc);

void gpio_pwm_set_duty(gpio_pwm_desc *desc, int ticks);
void gpio_pwm_set_period(gpio_pwm_desc *desc, int ticks);
void gpio_pwm_set_polarity(gpio_pwm_desc *desc, int polarity);

void gpio_pwm_release(gpio_pwm_desc*);

#endif
